using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/// \class  gkSpawner
/// \brief  Base class for managing the spawning of actor
[AddComponentMenu("GK/Engine/Game/Spawn/gkSpawner")]
public class gkSpawner : MonoBehaviour 
{
    /// The modifier of spawning behavior
    private gkSpawningModifier[] m_rSpawningModifiers;

    /// The class selector
    private gkSpawnClassSelector m_rSpawnClassSelector;

    /// \brief  Called just after the game begin to play
    void Start()
    {
        // Get the physic component
        m_rSpawnClassSelector = GetComponent<gkSpawnClassSelector>();

        m_rSpawningModifiers = GetComponents<gkSpawningModifier>();
    }

    /// \brief  Spawn randomly an actor
    public GameObject SpawnActor(int a_iNumActorsInBatch, int a_iNbActorsInBatch)
    {
	    GameObject rSpawnedActor;

	    // Spawn
        rSpawnedActor = Instantiate(m_rSpawnClassSelector.SelectSpawnClass()) as GameObject;
    	rSpawnedActor.transform.position = transform.position;
		
	    // Loop through the spawning modifiers and apply their modifications
        foreach (gkSpawningModifier rSpawningModifier in m_rSpawningModifiers)
	    {
		    rSpawningModifier.ModifySpawnedActor(rSpawnedActor, a_iNumActorsInBatch, a_iNbActorsInBatch);
	    }

	    return rSpawnedActor;
    }
}